package tliasmanagement.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override
    // 初始化方法, web服务器启动, 创建Filter实例时调用, 只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init ...");
//        Filter.super.init(filterConfig);
    }

    // 拦截到请求时,调用该方法,可以调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("doFilter ...");
        // 放行
        filterChain.doFilter(servletRequest, servletResponse);
    }

    // 销毁方法, web服务器关闭时调用, 只调用一次
    @Override
    public void destroy() {
        log.info("destroy ...");
//        Filter.super.destroy();
    }
}
